<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客正文</title>
    <link rel="stylesheet" href="css/conmmon.css">
    <link rel="stylesheet" href="css/blog_content.css">
    <link rel="stylesheet" href="editor.md/css/editormd.preview.min.css" />

    <script src="js/jquery.min.js"></script>
    <script src="js/urlutils.js"></script>
    <script src="editor.md/editormd.js"></script>
    <script src="editor.md/lib/marked.min.js"></script>
    <script src="editor.md/lib/prettify.min.js"></script>

</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/log.jpg" alt="">
        <span class="title">我的博客系统</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <a href="blog_list.html">主页</a>
        <a href="blog_add.html">写博客</a>
    </div>
    <!-- 版心 -->
    <div class="container">
        <!-- 左侧个人信息 -->
        <div class="container-left">
            <div class="card">
                <img src="*" class="avtar" alt="" id="photo">
<!--                  名字-->
                <h3 id="article"></h3>
                <a href="http:www.github.com">github 地址</a>
                <div class="counter">
                    <span>文章</span>
                </div>
                <div class="counter">
                    <span id="num"></span>
                </div>
            </div>
        </div>
        <!-- 右侧内容详情 -->
        <div class="container-right">
            <div class="blog-content">
                <!-- 博客标题 -->
                <h3 id="title"></h3>
                <!-- 博客时间 -->
                <div class="date" >
                    发布时间：<span id="createTime"></span>|
                    阅读量：<span id="rcount"></span>
                </div>
                <!-- 博客正文 -->
                <div id="editorDiv">

                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
            var editormd;
            function initEdit(md){
                editormd = editormd.markdownToHTML("editorDiv", {
                markdown : md, // Also, you can dynamic set Markdown text
                // htmlDecode : true,  // Enable / disable HTML tag encode.
                // htmlDecode : "style,script,iframe",  // Note: If enabled, you should filter some dangerous HTML tags for website security.
                });
            }
            var num=getParamValue("id");

            $.post("/art/getlist",{
                    "aId":num,
                    "ceo":1
                }, function (res){
                    if(res.code==200 && res.data!=null){
                        var art=res.data.art;
                        var user=res.data.user;
                        if(art!=null) {
                            jQuery("#title").html(art.title);
                            jQuery("#createTime").html(art.createtime);
                            jQuery("#rcount").html(art.rcount);   //阅读数
                            initEdit(art.content);
                        }else{
                            alert("抱歉，查询失败"+res.msg);
                            window.location.href="blog_list.html";
                        }
                        if(user!=null){
                            // 给用户对象设置值
                            jQuery("#article").html(user.uname);
                            jQuery("#num").html(user.count);
                            jQuery("#photo").attr('src',user.photo);
                        }else{
                            alert("抱歉：查询失败！"+res.msg);
                            window.location.href="blog_list.html";
                        }
                        incrementRCount();
                    }else{
                        alert("查询失败！"+res.msg);
                        location.href="login.html";
                    }

                }
            )

            //访问量加1
            function incrementRCount(){

                if(num==null || num<=0){
                    return false;
                }
                $.post("art/increment",{
                    "id":num
                },function (res){
                    if(res.code==200){

                    }else{
                        alert("访问出错");
                        location.href="blog_list.html";
                    }
                })
            }





    </script> 
</body>

</html>